package com.adtec.base.cloud.comminicate.communicate.commonlyused.service.impl;

import com.adtec.base.cloud.comminicate.communicate.commonlyused.service.CommonlyUsedService;
import com.adtec.base.cloud.persistence.communicate.mapper.CommCommonlyusedMapper;
import com.adtec.base.cloud.persistence.communicate.mapper.MyCommMapper;
import com.adtec.base.cloud.persistence.communicate.model.CommCommonlyused;
import com.adtec.base.cloud.persistence.system.model.SysDict;
import com.adtec.base.cloud.persistence.system.model.SysUserOrg;
import com.adtec.base.cloud.security.jwt.utils.GetUserId;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.Resource;

@Component
public class CommonlyUsedServiceImpl implements CommonlyUsedService {

    @Resource
    private GetUserId getUserId;

    @Resource
    private CommCommonlyusedMapper commCommonlyusedMapper;

    @Resource
    private MyCommMapper myCommMapper;

    @Override
    public void add(CommCommonlyused commCommonlyused) {
        commCommonlyusedMapper.insert(commCommonlyused);
    }

    @Override
    public void delete(Long id) {
        Assert.isTrue(id != null,
                "删除数据必须指定数据删除条件（主键）");
        commCommonlyusedMapper.deleteById(id);
    }

    @Override
    public void update(CommCommonlyused commCommonlyused) {
        Assert.isTrue(commCommonlyused.getId() != null,
                "更新数据必须指定数据更新条件（主键）");
        commCommonlyusedMapper.updateById(commCommonlyused);
    }

    @Override
    public IPage<CommCommonlyused> queryCommonlyUsed(Long id,
                                               String webUrl,
                                               String webName,
                                               String webDesc,
                                               Integer pageNum,
                                               Integer pageSize) {
        Page<CommCommonlyused> page = new Page<>(pageNum, pageSize);   //查询第pageNum页，每页pageSize条数据

        return myCommMapper.selectUrl(page, id, webUrl, webName, webDesc);
    }
}
